package com.vcit.clazz.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vcit.common.annotation.Log;
import com.vcit.common.core.controller.BaseController;
import com.vcit.common.core.domain.AjaxResult;
import com.vcit.common.enums.BusinessType;
import com.vcit.system.domain.clazz.TClazzRule;
import com.vcit.system.service.clazz.ITClazzRuleService;
import com.vcit.common.utils.poi.ExcelUtil;
import com.vcit.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 分班规则Controller
 *
 * @author vcit
 * @date 2025-01-17
 */
@Api("分班规则管理")
@RestController
@RequestMapping("/system/clazz/rule")
public class TClazzRuleController extends BaseController {
    @Autowired
    private ITClazzRuleService tClazzRuleService;

    /**
     * 查询分班规则列表
     */
    @ApiOperation("获取分班规则列表")
    @PreAuthorize("@ss.hasPermi('system:clazz:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(TClazzRule tClazzRule) {
        startPage();
        List<TClazzRule> list = tClazzRuleService.selectTClazzRuleList(tClazzRule);
        return getDataTable(list);
    }

    /**
     * 导出分班规则列表
     */
    @PreAuthorize("@ss.hasPermi('system:clazz:rule:export')")
    @Log(title = "分班规则", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TClazzRule tClazzRule) {
        List<TClazzRule> list = tClazzRuleService.selectTClazzRuleList(tClazzRule);
        ExcelUtil<TClazzRule> util = new ExcelUtil<TClazzRule>(TClazzRule.class);
        return util.exportExcel(list, "分班规则数据");
    }

    /**
     * 获取分班规则详细信息
     */
    @ApiOperation("获取分班规则详细信息")
    @PreAuthorize("@ss.hasPermi('system:clazz:rule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(tClazzRuleService.selectTClazzRuleById(id));
    }

    /**
     * 新增分班规则
     */
    @ApiOperation("新增分班规则")
    @PreAuthorize("@ss.hasPermi('system:clazz:rule:add')")
    @Log(title = "分班规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TClazzRule tClazzRule) {
        tClazzRule.setCreateBy(getLoginUser().getUsername());
        return toAjax(tClazzRuleService.insertTClazzRule(tClazzRule));
    }

    /**
     * 修改分班规则
     */
    @ApiOperation("修改分班规则")
    @PreAuthorize("@ss.hasPermi('system:clazz:rule:edit')")
    @Log(title = "分班规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TClazzRule tClazzRule) {
        tClazzRule.setUpdateBy(getLoginUser().getUsername());
        return toAjax(tClazzRuleService.updateTClazzRule(tClazzRule));
    }

    /**
     * 删除分班规则
     */
    @ApiOperation("删除分班规则")
    @PreAuthorize("@ss.hasPermi('system:clazz:rule:remove')")
    @Log(title = "分班规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tClazzRuleService.deleteTClazzRuleByIds(ids));
    }

    /**
     * 执行分班规则
     */
    @ApiOperation("执行分班规则")
    @PreAuthorize("@ss.hasPermi('system:clazz:rule:execute')")
    @Log(title = "分班规则", businessType = BusinessType.UPDATE)
    @PostMapping("/execute/{id}")
    public AjaxResult execute(@PathVariable("id") Long id) {
        return toAjax(tClazzRuleService.executeClazzRule(id));
    }
} 